package com.smh.demo1.a20;

import org.springframework.beans.BeanWrapperImpl;

import java.util.Date;

/**
 * @author shiminghui
 * @date 2025/5/1 14:56
 * @description: TODO
 */
public class TestBeanWrapper {
    public static void main(String[] args) {

        MyBean myBean = new MyBean();
        // 利用getter和setter方法进行赋值的
        BeanWrapperImpl beanWrapper = new BeanWrapperImpl(myBean);

        // 底层会使用转换器进行类型的转化
        beanWrapper.setPropertyValue("age", "12");
        beanWrapper.setPropertyValue("name", "shiminghui");
        beanWrapper.setPropertyValue("birthDate", "2004/10/26");

        System.out.println(myBean);

    }

    static class MyBean {
        private int age;
        private String name;
        private Date birthDate;

        @Override
        public String toString() {
            return "MyBean{" +
                    "age=" + age +
                    ", name='" + name + '\'' +
                    ", birthDate=" + birthDate +
                    '}';
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Date getBirthDate() {
            return birthDate;
        }

        public void setBirthDate(Date birthDate) {
            this.birthDate = birthDate;
        }
    }

}
